<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* canvas-style */

        /* 设置空的source图层 */
        let source = new ol.source.Vector({})
        let layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer)
        /* canvas-style */
        let canvas_size = 50;
        let canvas = document.createElement("canvas");
        canvas.width = canvas_size;
        canvas.height = canvas_size;
        /* 设置半径 */
        let radius = canvas_size / 4;
        let x = canvas_size / 2, y = canvas_size / 2
        /* 绘制 */
        let ctx = canvas.getContext("2d");
        ctx.beginPath();
        ctx.arc(x, y, radius, 0, Math.PI * 2);
        // ctx.arc(x, y, radius, 0, Math.PI * 2);
        ctx.closePath();
        ctx.fillStyle = "#ff2d51";
        ctx.fill();
        /* 设置canvas元素为openlayers的样式 */
        let style = new ol.style.Style({
            image: new ol.style.Icon({
                img: canvas,
                imgSize: [canvas.width, canvas.height],
                // imgSize: [canvas.width/2, canvas.height/2]
            })
        })
        var point = new ol.Feature({
            geometry: new ol.geom.Point([114.30, 30.50])
        })
        point.setStyle(style);
        // layer.setStyle(style);
        source.addFeature(point);
    </script>
</body>

</html>